<?php
/**
 * Created by PhpStorm.
 * User: asus
 * Date: 2017/3/20
 * Time: 10:45
 */

namespace Home\Controller;


class MyController extends NavController{
    public function __construct()
    {
        parent::__construct();
        $memberId = session('m_id');
        if(!$memberId){
            session('returnUrl',U('My/'.ACTION_NAME));
            redirect(U('Member/login'));
        }
    }

    public function order(){
        $orderModel = D('Admin/Order');
        $data = $orderModel->search();
        $this->assign(array(
           'data' => $data,
            '_page_title' => '个人中心-我的订单',
        ));
        $this->display();
    }

    public function order_detail(){
        $orderId = I('get.order_id',0);
        $orderModel = D('Admin/Order');
        $orderData = $orderModel->getDetail($orderId);

        $this->assign(array(
            'order' => $orderData,
            '_page_title' => '个人中心-订单详情',
        )); //var_dump($orderData);exit;
        $this->display();
    }

    public function setReceived(){
        $orderId = I('get.id');
        $model = D('Admin/Order');
        $data['post_status'] = 2;
        if($model->where('id='.$orderId)->save($data)){
            $this->success('确认收货成功！',U('order_detail',array('id'=>I('get.id'))));
            exit;
        }
        $this->error($model->getError());

    }

}